# 作者: 菅世博
# 2025年02月20日14时13分10秒
# 512326042@qq.com

# 士兵与枪
class Gun:
    def __init__(self, model):
        self.model = model
        self.bullet_count = 0

    def add_bullet(self, count):
        self.bullet_count += count

    def shoot(self):
        if self.bullet_count <= 0:
            print(f"{self.model}没有子弹了")
            return
        self.bullet_count -= 1
        print(f"{self.model}突突突,剩余子弹{self.bullet_count}")


class Soldier:
    def __init__(self, name):
        self.name = name
        self.gun = None

    def fire(self):
        if self.gun is None:
            print(f"{self.name}没有枪")
            return
        # 2. 高喊口号
        print("冲啊...[%s]" % self.name)
        # 3. 让枪装填子弹
        self.gun.add_bullet(50)
        # 4. 让枪发射子弹
        self.gun.shoot()


if __name__ == '__main__':
    gun = Gun("AK47")
    gun.add_bullet(50)
    # gun.shoot()
    soldier = Soldier("许三多")
    soldier.gun = gun #捡抢
    soldier.fire()
    print(soldier.gun)